<?php

$t_id_video = $_GET['id_video'];

if($t_id_video != "") {
  $query = getVideo($t_id_video);
  $fetch = MySQL_Fetch_Array($query);
  $t_nazev = $fetch["NAZEV"];
  $t_datum = substr($fetch["DATUM"], 0, 16);
  $t_soubor = $fetch["SOUBOR"];
  $t_id_clanek = $fetch["ID_CLANEK"];
} else {
  $t_nazev = "";
  $t_datum = StrFTime("%Y-%m-%d %H:%M", Time());
  $t_soubor = "";
  $t_id_clanek = -1;
}

if ($handle = opendir(VIDEO_GALLERY_PATH)) {
  while ($file = readdir($handle)){
      $polozky[count($polozky)] = $file;
  }
  closedir($handle);
  sort($polozky);
}

reset($polozky);

$pripony = array ("flv");

?>

<script language="JavaScript" type="text/javascript" src="./js/calendar.js">
</script>

<form name="formAdminNoveVideo" action="<? echo redirect_str(PAGE_ADMIN_VIDEOS).action(ACTION_SAVE_VIDEO); ?>" method="post">
  
  <input type="hidden" name="t_id_video" value="<? echo $t_id_video;?>">
  
  <fieldset>
    <legend><? echo ($t_id_video!=""?"úprava videa":"nové video"); ?></legend>
    
    <table class="panel-70">
      <tr>
        <td class="righted">název</td>
        <td><input class='text px170' type='text' name="t_nazev" value="<? echo $t_nazev;?>"></td>
      </tr>
      
      <tr>
        <td class="righted">datum</td>
        <td>
          <input class='text px170' type='text' name="t_datum" maxlength="16" value="<? echo $t_datum;?>">
          <img class="icon-btn" onClick="ShowCalendar('formAdminNoveVideo', 't_datum', false)" src="./img/icons/calendar.gif">
        </td>
      </tr>
      
      <tr>
        <td class="righted">soubor videa</td>
        <td>
          <select class="text" name='t_soubor' size=1>
            <option value="-1">není</option>
            <?
            while (list($key, $val) = each($polozky)) {
              $str = explode (".", $val);
              if ($val != "." && $val != ".." && in_array($str[1], $pripony)) {
                if (!is_dir($val)) {
                    if($val == $t_soubor)  echo "<option value='$val' selected>$val</option>";
                    else echo "<option value='$val'>$val</option>";
                }
               }
            }
            ?>
          </select>
        </td>
      </tr>
      
      <tr>
        <td class="righted">připojit k článku</td>
        <td>
          <select class="text" name='t_id_clanek' size=1>
            <option value='-1'>nepřipojit</option>;
            <?
            $query = getAllClanky();
            while($fetch = MySQL_Fetch_Array($query)){
              $id_clanku = $fetch["ID_CLANKU"];
              $title = $fetch["NADPIS"];
              if(strlen($title) > 25) $title = substr($title, 0, 25)."...";
              $text = DateFormat::format($fetch["CAS_UPRAVY"], DF_DDMMYYYY)."\t".$title; 
              if($t_id_clanek == $id_clanku) echo "<option value='$id_clanku' selected>$text</option>";
              else echo "<option value='$id_clanku'>$text</option>";
            }
            ?>
          </select>
        </td>
      </tr>
      
      <tr>
        <td colspan="2">
        <div class="center">
        	<input class="button" onmouseover="this.className='button_hover'" 
       			onmouseout="this.className='button'" type="submit" value="ULOŽIT">
       		<a class="button preloader" href="<? echo redirect_str(PAGE_ADMIN_VIDEOS); ?>">ZRUŠIT</a>
        </div>
        </td>
      </tr>
    </table>
  </fieldset>
</form>